<template>
  <div class="exhibits-box">
    <div class="textMax-box" ref="exhibits1Box">
      <titles :title="props.info.text" />
      <div class="subTitle" v-if="props.info.subTitle">——{{ props.info.subTitle }}</div>
      <div style="width: 980px; margin: 20px auto 0">
        <textMax v-if="props.info.remarks" :data="props.info.remarks" :maxLen="121" :tip="''" />
      </div>
    </div>
    <exhibitCom2Vue v-if="props.tabDatas.length === 2" :info="props.info" :tabDatas="tabDatas"></exhibitCom2Vue>
    <exhibitCom3Vue v-if="props.tabDatas.length === 3" :info="props.info" :tabDatas="tabDatas"></exhibitCom3Vue>
    <exhibitCom4Vue v-if="props.tabDatas.length === 4" :info="props.info" :tabDatas="tabDatas"></exhibitCom4Vue>
    <exhibitCom5Vue v-if="props.tabDatas.length === 5" :info="props.info" :tabDatas="tabDatas"></exhibitCom5Vue>
    <exhibitCom6Vue v-if="props.tabDatas.length === 6" :info="props.info" :tabDatas="tabDatas"></exhibitCom6Vue>

    <div
      style="cursor: pointer"
      @click="pathChild"
      :style="{
        fontSize: store.styleInfo.mintitleSize,
        color: '#fff',
      }"
      class="left-btn flex-c-c-c"
    >
      <div class="btn-img">
        <buttonIcon />
      </div>
      <span>查看全部</span>
    </div>
  </div>
</template>
<script setup lang="ts">
import { pathList, pathListLoop } from '../route';
import { urls } from '@/utils/request/upload';
import titles from '@/components/title/title.vue';
import buttonIcon from '@/components/title/buttonIcon.vue';
import { handlemouse } from '@/utils/minxin';
import { onMounted, ref } from 'vue';
import { useProjectStore } from '@/store';
import { useRouter, useRoute } from 'vue-router';
import textMax from '@/components/textMax/textMax.vue';
import exhibitCom2Vue from './exhibits1/exhibits1Com2.vue';
import exhibitCom3Vue from './exhibits1/exhibits1Com3.vue';
import exhibitCom4Vue from './exhibits1/exhibits1Com4.vue';
import exhibitCom5Vue from './exhibits1/exhibits1Com5.vue';
import exhibitCom6Vue from './exhibits1/exhibits1Com6.vue';
const route = useRoute();
const router = useRouter();
const store = useProjectStore();
const exhibits1Box = ref(null);
const props = defineProps({
  info: {
    type: Object,
  },
  tabDatas: {
    type: Array,
  },
});
const pathChild = () => {
  store.setchildModel(props.info);
  store.setCurrent(0);
  router.push({
    name: route.meta.loopType ? pathListLoop[8] : pathList[8],
    query: { childId: props.info.id },
  });
};
onMounted(() => {
  animation();
});
const animation = () => {
  let canTrigger = true; // 标记是否可以触发

  const observer = new IntersectionObserver((entries) => {
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码s
        // console.log('c', exhibitsBox.value);
        exhibits1Box.value.classList.add('animation-box');

        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        // if (exhibits1Box.value) {
        //   exhibits1Box.value.classList.remove('animation-box');
        // }
      }
    });
  });
  observer.observe(exhibits1Box.value);
};
</script>
<style scoped lang="less">
@import './index.less';
.exhibits-box {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.textMax-box {
  width: 1180px;
  min-height: 112px;
  :deep(.tj) {
    line-height: 32px;
  }
}
.animation-box {
  animation: slideIn 1s forwards;
}
@keyframes slideIn {
  0% {
    // padding-right: 980px;
    transform: translateX(-100%); /* 元素初始位置 */
    opacity: 0;
  }
  100% {
    padding-right: 0px;
    opacity: 1;
    transform: translateX(0); /* 元素最终位置 */
  }
}
</style>
